package com.icinfo.cloud.provider.common.enums;

import org.springframework.util.ObjectUtils;

/**
 * @author shishengyao
 * @description
 * @date 2022/4/19
 */
public enum DocumentTemplateKindEnum {
    /**
     * 模板类别：1 标准表单模板 2 标准文书模板 3窄幅表单模板 4窄幅文书模板
     */
    STANDARD_TEMPLATE("standard", "标准模板"),
    NARROW_TEMPLATE("narrow", "窄幅模板");

    /**
     * 编码
     */
    private String code;
    /**
     * 描述
     */
    private String des;

    DocumentTemplateKindEnum(String code, String des) {
        this.code = code;
        this.des = des;
    }

    /**
     * 根据code获取value
     *
     * @param code 编码
     * @return {@link String }
     * @author shishengyao
     * @date 2022/02/23
     */
    public static String getValueByCode(String code) {
        if (ObjectUtils.isEmpty(code)) {
            return null;
        }
        for (DocumentTemplateKindEnum e : DocumentTemplateKindEnum.values()) {
            if (code.equals(e.getCode())) {
                return e.getDes();
            }
        }
        return null;
    }

    /**
     * 描述：校验code是否是合法枚举
     *
     * @param code 枚举code
     * @return boolean
     * @author shishengyao
     * @date 2022/02/23
     */
    public static boolean isLegalEnumCode(String code) {
        boolean flag = false;
        for (DocumentTemplateKindEnum e : DocumentTemplateKindEnum.values()) {
            if (e.getCode().equalsIgnoreCase(code)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDes() {
        return des;
    }

    public void setDes(String des) {
        this.des = des;
    }
}
